This page has been superceded by a wiki version of this example: StringComparisonOperatorsExample





/*



Title:      String Operations

File:       string_ops.d

Author:     J C Calvarese, http://jcc_7.tripod.com/d/

Date:       2003/10/07

License:    Public Domain



*/





int main()

{

    char[] str1 = "Aardvark";

    char[] str2 = "Zebra";

    char[] str3 = "1";

    

    

    /* "less than" operator */

    

    if ( str1 < str2 ) 
      printf("Aardvark comes before Zebra.\n");
    else

      printf("Aardvark comes after Zebra.\n");
    

    

    /* "greater" than operator */

    

    if ( str1 > str2 ) 
      printf("Aardvark comes after Zebra.\n");
    else

      printf("Aardvark comes before Zebra.\n");
    

    

    /* "equality" operator */

    

    if ( str1 == str2 ) 
      printf("Aardvark is Zebra?!\n");
    else

      printf("Aardvark is NOT Zebra.\n");

    

    

    /* "concatenation" operator */

    

    for (int i=0; i<3; i++) 
      str3 ~= "0";

    printf("%.*s\n", str3);

    

    return 0;

}